package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketFootprint;
import com.cskaoyan.market.db.domain.MarketFootprintExample;
import com.cskaoyan.market.db.domain.MarketSearchHistory;
import com.cskaoyan.market.db.domain.MarketSearchHistoryExample;
import com.cskaoyan.market.db.mapper.MarketFootprintMapper;
import com.cskaoyan.market.db.mapper.MarketSearchHistoryMapper;
import com.cskaoyan.market.service.AdminHistoryService;
import com.cskaoyan.market.util.MybatisUtil;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminHistoryServiceImpl implements AdminHistoryService {
    @Override
    public List<MarketSearchHistory> list(String page, String limit, String userId, String keyword, String sort, String order) {
        SqlSession session = MybatisUtil.getSession();
        MarketSearchHistoryMapper mapper = session.getMapper(MarketSearchHistoryMapper.class);
        MarketSearchHistoryExample marketSearchHistoryExample = new MarketSearchHistoryExample();
        MarketSearchHistoryExample.Criteria criteria = marketSearchHistoryExample.createCriteria();
        if(!StringUtils.isEmpty(userId))
            criteria.andUserIdEqualTo(Integer.parseInt(userId));
        if(!StringUtils.isEmpty(keyword))
            criteria.andUserIdEqualTo(Integer.parseInt(keyword));
        marketSearchHistoryExample.setOrderByClause(sort + " " + order);
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));
        List<MarketSearchHistory> marketSearchHistoryList = mapper.selectByExample(marketSearchHistoryExample);
        session.commit();
        session.close();
        return marketSearchHistoryList;
    }
}
